package com.woniuxy.controller;

import com.woniuxy.entity.Department;
import com.woniuxy.service.DepartmentService;
import com.woniuxy.util.Result;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：zhaisir
 * @date ：Created in 2023/2/11 11:14
 * @description：
 * @modified By：
 * @version: $
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("department/")
public class DepartmentController {
    @NonNull
    private DepartmentService departmentService;

    @PutMapping("add")
    public Result add(@RequestBody Department department){
        int i = departmentService.insertSelective(department);
        return Result.ok();
    }
    @DeleteMapping("del/{id}")
    public Result del(@PathVariable long id){
        int i = departmentService.deleteByPrimaryKey(id);
        return Result.ok();
    }
    @PostMapping("update")
    public Result update(@RequestBody Department department){
        int i = departmentService.updateByPrimaryKeySelective(department);
        return Result.ok();
    }
    @GetMapping("selOne/{id}")
    public Result selOne(@PathVariable long id){
        Department department1 = departmentService.selectByPrimaryKey(id);
        return Result.ok().data("department1",department1);
    }
    @GetMapping("selectAll")
    public Result selectAll(){
        List<Department> list = departmentService.selectAll();
        return Result.ok().data("deptList",list);
    }
}
